package com.google.android.gcm.demo.app;

import java.util.regex.Pattern;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.util.Patterns;

public class DeviceInfoUtil {
	
	public static String getDeviceEmail(Context context){
		String deviceEmail = null;
		Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
		Account[] accounts = AccountManager.get(context).getAccounts();
		for (Account account : accounts) {
		    if (emailPattern.matcher(account.name).matches() && account.name.contains("gmail")) {
		    	deviceEmail = account.name;
		        return deviceEmail;
		    }
		}
		return deviceEmail;
	}
	
}
